package kr.saeildamil.androidstudy_second24;

import java.util.ArrayList;

import kr.saeildamil.androidstudy_second.R;
import android.animation.Animator;
import android.animation.AnimatorInflater;
import android.animation.AnimatorSet;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.app.Activity;
import android.content.Context;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;

public class XmlAnim extends Activity {
	AnimView mView;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch24_ballanim);
		
		LinearLayout root=(LinearLayout) findViewById(R.id.ch24_ballanim_layout);
		mView=new AnimView(this);
		root.addView(mView);
	}
	public void mOnClick(View v){
		mView.startAnim();
	}
	public class AnimView extends View{
		Ball mBall;
		public AnimView(Context context) {
			super(context);
			mBall=new Ball();
			mBall.setX(100);
			mBall.setY(50);
			mBall.setRad(20);
		}
		public void startAnim() {
			mBall.setX(100);
			mBall.setY(50);
			mBall.setRad(20);
			
			AnimatorSet set=(AnimatorSet) AnimatorInflater.loadAnimator(XmlAnim.this, R.anim.rightsownlarge);
			set.setTarget(mBall);
			ArrayList<Animator>childs=set.getChildAnimations();
			set.start();
		}
		AnimatorUpdateListener mInvalator=new AnimatorUpdateListener() {
			
			@Override
			public void onAnimationUpdate(ValueAnimator animation) {
				invalidate();
			}
		};
		protected void onDraw(android.graphics.Canvas canvas) {
			Paint mPaint=new Paint();
			mPaint.setColor(mBall.getColor());
			mPaint.setAntiAlias(true);
			canvas.drawCircle(mBall.getX(), mBall.getY(), mBall.getRad(), mPaint);
			
		};
		
	}
}
